package com.yungu.swift.api.route.v2.passenger;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yungu.swift.api.base.BaseApi;
import com.yungu.swift.autoconfig.redis.RedisCacheService;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.constants.CommonConstant;
import com.yungu.swift.order.model.param.JoinOrderParam;
import com.yungu.swift.order.model.vo.JsonOrderDetailVo;
import com.yungu.swift.order.service.OrderFareService;
import com.yungu.swift.order.service.OrderJoinService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping(value = "/api/v2/passenger/token/join/order/parcel")
@Api(value = "【乘客】【订单】【跨城小件】乘客跨城小件订单接口V2", tags = "V2-乘客跨城小件订单接口")
public class PasOrderParcelApi extends BaseApi {

    @Autowired
    private RedisCacheService redisCacheService;
    @Reference
    private OrderJoinService orderJoinService;
    @Reference
    private OrderFareService orderFareService;


    @PostMapping(value = {"/evaluateNew"})
    @ApiOperation(value = "估价接口 —— 已生效", response = Map.class, notes = "响应数据结构参照专/快车系列，以实际接口返回为准")
    public ResponseData<Map<String, Object>> parcelEvaluate(@RequestBody JoinOrderParam joinOrdeParam) {
        joinOrdeParam.setPassengerUuid(joinOrdeParam.getUserUuid());
        return orderFareService.parcelValuation(joinOrdeParam);
    }

    @PostMapping(value = {"/createNew"})
    @ApiOperation(value = "创建订单接口 —— 已生效", response = JsonOrderDetailVo.class)
    public ResponseData<Map<String,Object>> createParcelOrder(@RequestBody JoinOrderParam joinOrdeParam) {
        joinOrdeParam.setPassengerUuid(joinOrdeParam.getUserUuid());
        joinOrdeParam.setTypeModule(CommonConstant.BUSINESS_TYPE_PARCEL);
        ResponseData<Map<String,Object>> responseData = orderJoinService.createCrosstownOrder(joinOrdeParam);
        if (responseData.isSuccess() && responseData.getData() != null) {
            redisCacheService.set(responseData.getData().get("orderUuid").toString(), joinOrdeParam, 10L);
        }
        return responseData;
    }

    @PostMapping(value = {"/tagNew"})
    @ApiOperation(value = "跨城小件标签获取接口")
    public ResponseData<Map<String, Object>> getParcelTag(@RequestBody JoinOrderParam joinOrdeParam) {
        return orderJoinService.getParcelTag(joinOrdeParam);
    }

    @PostMapping(value = {"/getReceiptCodeNew"})
    @ApiOperation(value = "乘客获取收件码接口")
    public ResponseData<List<Map<String, Object>>> getReceiptCode(@RequestBody JoinOrderParam joinOrdeParam) {
        return orderJoinService.getReceiptCode(joinOrdeParam);
    }

}
